import 'package:flutter/material.dart';
import 'package:jd_shopping/services/ScreenAdaper.dart';
import 'package:provider/provider.dart';
import 'package:jd_shopping/pages/CartShop/CartItem.dart';
import 'package:jd_shopping/pages/Providers/CartShow.dart';

class PayPage extends StatefulWidget {
  @override
  _PayPageState createState() => _PayPageState();
}

class _PayPageState extends State<PayPage> {
  @override
  Widget build(BuildContext context) {
    ScreenAdaper.init(context);
    var cartProvider = Provider.of<CartsShow>(context);
    return Scaffold(
      appBar: AppBar(title: Text('订单页面')),
      body: Stack(
        children: [
          ListView(
            children: [
              SizedBox(height: ScreenAdaper.height(30)),
              InkWell(
                child: Container(
                    padding: EdgeInsets.all(20), height: ScreenAdaper.height
                   (150),
                    color: Colors.white,
                    child: Stack(
                      children: <Widget>[
                        Align(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            "张三 15201681234\n北京市海定区西二旗",
                            style: TextStyle(color: Colors.black, fontSize: 20),
                          ),
                        ),
                        Align(
                          alignment: Alignment.centerRight,
                          child: Icon(Icons.arrow_forward_ios),
                        )
                      ],
                    )
                  ),
                  onTap:(){
                    Navigator.pushNamed(context,'/address');
                  },
              ),
              SizedBox(height: ScreenAdaper.height(30)),
              Column(
                children: cartProvider.cartList.map((value) {
                  return CartItem(value);
                }).toList(),
              ),
              SizedBox(height: ScreenAdaper.height(30)),
              Container(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      margin: EdgeInsets.fromLTRB(20, 0, 20, 0),
                      child: Text(
                        '商品总金额:￥${cartProvider.totalPrice}',
                        style: TextStyle(color: Colors.black, fontSize: 16),
                      ),
                    ),
                    Divider(),
                    Container(
                      margin: EdgeInsets.fromLTRB(20, 0, 20, 0),
                      child: Text('立减:￥0元',
                          style: TextStyle(color: Colors.black, fontSize: 16)),
                    ),
                    Divider(),
                    Container(
                      margin: EdgeInsets.fromLTRB(20, 0, 20, 0),
                      child: Text('运费:￥0元',
                          style: TextStyle(color: Colors.black, fontSize: 16)),
                    )
                  ],
                ),
                color: Colors.white,
              ),
            ],
          ),
          Positioned(
            bottom: 0,
            height: ScreenAdaper.height(80),
            width: ScreenAdaper.getScreenWidth(),
            child: Container(
              decoration: BoxDecoration(
                border:
                    Border(top: BorderSide(width: 1, color: Colors.black12)),
                color: Colors.white,
              ),
              width: ScreenAdaper.getScreenWidth(),
              height: ScreenAdaper.height(80),
              child: Stack(
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.fromLTRB(20, 0, 0, 0),
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: Row(
                        children: <Widget>[
                          Text("实付款:"),
                          Text(
                            '￥${cartProvider.totalPrice}',
                            style: TextStyle(color: Colors.red, fontSize: 20),
                          ),
                        ],
                      ),
                    ),
                  ),
                  Container(
                      margin: EdgeInsets.fromLTRB(0, 0, 20, 0),
                      child: Align(
                        alignment: Alignment.centerRight,
                        child: RaisedButton(
                          child: Text("立即下单",
                              style: TextStyle(color: Colors.white)),
                          color: Colors.red,
                          onPressed: () {
                              Navigator.pushNamed(context, '/payPage');
                          },
                        ),
                      )),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
